var t = getApp(), a = require("../../A4730AC3A71FB5DFC21562C4223CA4D1.js");

Page({
    data: {
        statusBarHeight: t.globalData.statusBarHeight,
        titleBarHeight: t.globalData.titleBarHeight,
        isGettingData: !1,
        getDefaultDataCount: 0,
        defaultData: [],
        showList: [],
        swiperImgs: [],
        themeImg: "",
        winWidth: t.globalData.windowWidth,
        isShowActivityTip: !1
    },
    onLoad: function(a) {
        var e = a.device_id;
        e && (t.globalData.deviceId = e);
        var i = Date.now(), n = new Date("2020-01-13 00:00:00").getTime(), s = new Date("2020-02-01 00:00:00").getTime();
        i >= n && i < s && this.setData({
            isShowActivityTip: !0
        });
    },
    onShow: function() {
        var a = t.globalData.defaultClothingData;
        a ? this.setData({
            defaultData: a
        }) : this.getDefaultData(), this.data.showList.length || this.getShowList(), this.data.swiperImgs.length || this.getSwiperImgs();
    },
    onShareAppMessage: function() {
        return {
            title: "自造衫店，随时随地，自由定制高品质T恤！",
            imageUrl: "../../assets/images/share_app.jpg",
            query: ""
        };
    },
    onPullDownRefresh: function() {
        this.data.isGettingData && this.data.getDefaultDataCount > 0 || (this.setData({
            getDefaultDataCount: 0,
            isGettingData: !0
        }), this.getDefaultData(!0), this.getSwiperImgs(!0), this.getShowList(!0));
    },
    handleType: function(t) {
        var a = t.currentTarget.dataset, e = a.type, i = a.nav, n = a.position;
        if (this.data.defaultData.length) {
            var s = "";
            s = "detail" === i ? "/pages/shirt/index?clothing=" + e + "&position=" + n : "/pages/diy/diy?clothing=" + e + "&position=" + n, 
            wx.navigateTo({
                url: s
            });
        } else wx.showToast({
            title: "正在加载数据中，请稍后重试",
            icon: "none"
        });
    },
    getShowList: function(t) {
        var e = this;
        a.get("/v2/goodslist").then(function(a) {
            if (t) {
                var i = e.data.getDefaultDataCount;
                i < 2 ? e.setData({
                    getDefaultDataCount: i + 1
                }) : (wx.stopPullDownRefresh(), e.setData({
                    getDefaultDataCount: 0,
                    isGettingData: !1
                }));
            }
            if (1001 === a.data.code) {
                var n = a.data.response.data;
                e.setData({
                    showList: n
                });
            }
        }).catch(function() {
            if (t) {
                var a = e.data.getDefaultDataCount;
                a < 2 ? e.setData({
                    getDefaultDataCount: a + 1
                }) : (wx.stopPullDownRefresh(), e.setData({
                    getDefaultDataCount: 0,
                    isGettingData: !1
                }));
            }
        });
    },
    getDefaultData: function(e) {
        var i = this;
        a.get("/v2/goods").then(function(a) {
            if (e) {
                var n = i.data.getDefaultDataCount;
                n < 2 ? i.setData({
                    getDefaultDataCount: n + 1
                }) : (wx.stopPullDownRefresh(), i.setData({
                    getDefaultDataCount: 0,
                    isGettingData: !1
                }));
            }
            if (1001 === a.data.code) {
                var s = a.data.response.data;
                t.globalData.defaultClothingData = s, i.setData({
                    defaultData: s
                });
            }
        }).catch(function() {
            if (e) {
                var t = i.data.getDefaultDataCount;
                t < 2 ? i.setData({
                    getDefaultDataCount: t + 1
                }) : (wx.stopPullDownRefresh(), i.setData({
                    getDefaultDataCount: 0,
                    isGettingData: !1
                }));
            }
        });
    },
    handleSwiperNav: function(t) {
        var a = t.currentTarget.dataset.content, e = {};
        try {
            e = JSON.parse(a);
        } catch (t) {}
        e.content && ("APPLET" === e.type ? wx.navigateTo({
            url: e.content
        }) : wx.navigateTo({
            url: "/pages/web/index?url=" + encodeURIComponent(e.content)
        }));
    },
    getSwiperImgs: function(t) {
        var e = this;
        a.get("/v2/advertisement", {
            type: 8
        }).then(function(a) {
            if (t) {
                var i = e.data.getDefaultDataCount;
                i < 2 ? e.setData({
                    getDefaultDataCount: i + 1
                }) : (wx.stopPullDownRefresh(), e.setData({
                    getDefaultDataCount: 0,
                    isGettingData: !1
                }));
            }
            if (1001 === a.data.code) {
                var n = [], s = "", o = !0, D = !1, u = void 0;
                try {
                    for (var g, l = a.data.response.data[Symbol.iterator](); !(o = (g = l.next()).done); o = !0) {
                        var r = g.value;
                        0 === r.advertisement_position ? s = r.advertisement_focusimg.normal : n.push(r);
                    }
                } catch (t) {
                    D = !0, u = t;
                } finally {
                    try {
                        !o && l.return && l.return();
                    } finally {
                        if (D) throw u;
                    }
                }
                e.setData({
                    swiperImgs: n,
                    themeImg: s
                });
            }
        }).catch(function() {
            if (t) {
                var a = e.data.getDefaultDataCount;
                a < 2 ? e.setData({
                    getDefaultDataCount: a + 1
                }) : (wx.stopPullDownRefresh(), e.setData({
                    getDefaultDataCount: 0,
                    isGettingData: !1
                }));
            }
        });
    },
    navToTeamBuying: function() {
        wx.navigateTo({
            url: "/pages/teamBuying/index"
        });
    },
    hideActivityTip: function() {
        this.setData({
            isShowActivityTip: !1
        });
    }
});